/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrameRelevantDocument.java
 *
 * Created on 13 Jun 09, 8:11:41
 */

package amd.ui;

import amd.core.UIListener;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author Latifah Dwi Nurachma
 */
public class FrameRelevantDocument extends javax.swing.JFrame {
    private UIListener listener;

    String inputKeyword;
    /** Creates new form FrameRelevantDocument */
    public FrameRelevantDocument(String inputKeyword) throws Exception {
        this.inputKeyword = inputKeyword;
        initComponents();
        fieldInputKeyword.setText(inputKeyword);
        listener = new UIListener(this);
        //searchDocumentByKeyword(inputKeyword);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fieldInputKeyword = new javax.swing.JTextField();
        buttonCari = new javax.swing.JButton();
        buttonUpload = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        buttonEkstrak = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("AMD_LSA");

        fieldInputKeyword.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                fieldInputKeywordFocusLost(evt);
            }
        });
        fieldInputKeyword.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                fieldInputKeywordKeyPressed(evt);
            }
        });

        buttonCari.setText("Cari");
        buttonCari.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                buttonCariMouseReleased(evt);
            }
        });

        buttonUpload.setText("Upload Dokumen");
        buttonUpload.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                buttonUploadMouseReleased(evt);
            }
        });

        buttonEkstrak.setText("Ekstrak");
        buttonEkstrak.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                buttonEkstrakMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fieldInputKeyword, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonCari)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonUpload)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonEkstrak)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(buttonCari)
                    .addComponent(fieldInputKeyword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonUpload)
                    .addComponent(buttonEkstrak))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(370, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonCariMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonCariMouseReleased
        searchDocument(inputKeyword);
    }//GEN-LAST:event_buttonCariMouseReleased

    private void buttonUploadMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonUploadMouseReleased
        listener.uploadDocument();
    }//GEN-LAST:event_buttonUploadMouseReleased

    private void fieldInputKeywordKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldInputKeywordKeyPressed
        char c = (char) evt.getKeyCode();
        if (c == KeyEvent.VK_ENTER) {
            inputKeyword = fieldInputKeyword.getText();
            searchDocument(inputKeyword);
        }
    }//GEN-LAST:event_fieldInputKeywordKeyPressed

    private void fieldInputKeywordFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_fieldInputKeywordFocusLost
        inputKeyword = fieldInputKeyword.getText();
    }//GEN-LAST:event_fieldInputKeywordFocusLost

    private void buttonEkstrakMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonEkstrakMouseReleased
        listener.ekstrakDokumen();
    }//GEN-LAST:event_buttonEkstrakMouseReleased

    private void searchDocument(String keyword) {
        if (!keyword.isEmpty()){
            listener.searchDocumentByKeyword(inputKeyword);
        }
        else{
            JOptionPane.showMessageDialog(this, "Keyword Kosong. \nHarap isi keyword dari dokumen yang akan dicari","Cari Dokumen",JOptionPane.WARNING_MESSAGE,null);
        }
    }

    public void showResult(){
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCari;
    private javax.swing.JButton buttonEkstrak;
    private javax.swing.JButton buttonUpload;
    private javax.swing.JTextField fieldInputKeyword;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

}
